function backDevice() {
	window.location.href = 'deviceRegister.jsp';
}

var treeId = sessionStorage.getItem("treeId") || '001';
var treeCode = sessionStorage.getItem("treeCode") || '001_';
var institutionId = sessionStorage.getItem("institutionId") || '1';

sessionStorage.setItem("treeId", '001');
sessionStorage.setItem("treeCode", '001_');
sessionStorage.setItem("institutionId", '1');

function institutionOpen() {
	if($(".userInstitution_float").css("display") == 'block') {
		$(".userInstitution_float").slideToggle();
		$(".userInstitution_reduce").addClass("userInstitution_add")
		$(".userInstitution_b_open").addClass("userInstitution_folder")
	} else {
		$(".userInstitution_float").slideToggle();
		$(".userInstitution_reduce").removeClass("userInstitution_add")
		$(".userInstitution_b_open").removeClass("userInstitution_folder")
	}
}

function checkInput(data) {
	console.log(data.id)
	$("#iAdd").attr("src", "userInstitutionAdd.jsp");
	$("#iAdd").reload();

}

$.ajax({
	url: 'orgListTree',
	type: 'POST',
	data: {
		companyId: $.Cookie("companyId"),
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
	},
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == -6) {
			alert("登陆超时！")
			top.location.href = 'index.jsp';

		} else if(data.errorCode == 0) {

			var setting = {
				data: {

					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeClick: beforeClick

				}
			};

			var zNodes = data.result

			var log, className = "dark";

			function beforeClick(treeId, treeNode, clickFlag) {

				sessionStorage.setItem("treeId", treeNode.orgId);
				sessionStorage.setItem("institutionId", treeNode.id);
				sessionStorage.setItem("treeCode", treeNode.treeCode);
				document.getElementById('iAdd').contentWindow.location.href = 'userInstitutionAdd.jsp';;
			}

			$(document).ready(function() {
				$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			});
		}
	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！")
		top.location.href = 'index.jsp';

	}
});